from app.app import Flask
from flask_cors import CORS

def register_blueprints(app):  # 蓝图注册函数
    from app.api.v1 import create_blueprint_v1
    app.register_blueprint(create_blueprint_v1(), url_prefix='/v1')

def register_plugin(app):
    from app.models.base import db
    db.init_app(app)
    with app.app_context():
        db.create_all()
def create_app():
    app = Flask(__name__)
    # 解决前端跨域问题，让当前系统的所有接口都可以跨域使用
    CORS(app, resources=r'/*')
    app.config.from_object('app.config.setting')
    app.config.from_object('app.config.secure')
    register_blueprints(app)  # 蓝图注册
    register_plugin(app)
    return app
